BruteForce::BruteForce( const char* input_file ) : Algorithm( input_file ){
	best_solution_cardinality = 0;
	timeout = false;
	
}

BruteForce::~BruteForce(){
}

void BruteForce::solve(){
	
	start_time = time(NULL);
		
	best_solution_cardinality = 0;
	
	Set s;
	recursiveSolve(s, 0, 0);
	cout << best_solution_cardinality;
	if(timeout)
		cout << "*";
	cout << " " << time(NULL) -start_time << endl;
	
}

list<int> sol;

void BruteForce::recursiveSolve( Set s, int set_index, int deepth ){
	if( time(NULL) - start_time >= 60 ){
		timeout = true;
		return;
	}
	
	if( deepth >= k ){
		if( s.cardinality() > best_solution_cardinality ){
			//*
			list<int>::iterator it = sol.begin();
			while( it != sol.end() ){
				cout << *it << " ";
				++it;
			}
			cout << endl;
			s.print();
			//*/
			best_solution_cardinality = s.cardinality();
		}
		return;
	}
		
	for( int i = set_index; i < L; ++i ){
		Set new_solution = s;
		if( deepth == 0 )
			new_solution.union_(&sets[i]);
		else
			new_solution.intersection(&sets[i]);
		
		if( new_solution.cardinality() < best_solution_cardinality)
			continue;
		sol.push_back(i);
		recursiveSolve( new_solution, i+1, deepth+1 );
		sol.pop_back();
	}
}

void BruteForce::printSolution( list<int>& solution ){
	Set* intersection = new Set();
	
	list<int>::iterator it = solution.begin();
	while( it != solution.end() ){
		cout << *it << " ";
		++it;
	}
	cout << endl;
}
